package com.yunsc.admin.controller.store;

import com.yunsc.common.utils.PageResult;
import com.yunsc.common.utils.Result;
import com.yunsc.common.utils.SecurityUtil;
import com.yunsc.common.validator.ValidationGroups;
import com.yunsc.store.dto.StoreDeliveryDTO;
import com.yunsc.store.entity.YunscDeliveryEntity;
import com.yunsc.store.service.YunscDeliveryService;
import com.yunsc.store.vo.StoreDeliveryVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @version: 1.0
 * @Author: adan
 * @description: 商家配送模板controller
 * @date: 2024-04-19 23:53
 */
@Api(value = "商家配送模板", tags = "商家信息接口")
@Slf4j
@RestController
@RequestMapping("delivery")
public class DeliveryController {


    @Resource
    private YunscDeliveryService deliveryService;

    /**
     * 配送列表
     */
    @ApiOperation("配送信息查询接口")
    @GetMapping("/all")
    public Result<?> queryDeliveryAll() {
        Integer currentStoreId = SecurityUtil.getCurrentStoreId();
        List<YunscDeliveryEntity> list = deliveryService.queryDeliveryAll(currentStoreId);
        return Result.resultList(list);
    }

    @ApiOperation("配送信息查询接口")
    @GetMapping("/list")
    public Result<?> queryDeliveryList(@RequestParam("page") Integer page,
                                  @RequestParam(value = "search", required = false) String search) {
        Integer currentStoreId = SecurityUtil.getCurrentStoreId();
        PageResult<YunscDeliveryEntity> list = deliveryService.queryDeliveryList(page, search, currentStoreId);
        return Result.resultPageList(list);
    }

    @ApiOperation("添加配送模板")
    @PostMapping("/add")
    public Result<?> saveDelivery(@RequestBody StoreDeliveryDTO deliveryParams) {
        deliveryService.saveDelivery(deliveryParams);
        return Result.ok();
    }

    @ApiOperation("修改配送模板")
    @PostMapping("/edit")
    public Result<?> updateDelivery(@RequestBody @Validated(ValidationGroups.Update.class) StoreDeliveryDTO deliveryParams) {
        deliveryService.updateDelivery(deliveryParams);
        return Result.ok();
    }
    @ApiOperation("删除配送模板")
    @PostMapping("/delete")
    public Result<?> deleteDelivery(@RequestBody @Validated(ValidationGroups.Delete.class) StoreDeliveryDTO deliveryParams) {
        deliveryService.deleteDeliveryById(deliveryParams.getDeliveryId());
        return Result.ok();
    }

    @ApiOperation("查询配送模板详情接口")
    @GetMapping("/detail")
    public Result<?> queryExpressDetail(@RequestParam("deliveryId") Integer deliveryId) {
        StoreDeliveryVO detail = deliveryService.queryDeliveryDetail(deliveryId);
        Map<String, Object> map = new HashMap<>();
        map.put("detail", detail);
        return Result.ok(map);
    }


}
